<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
        
// 应用公共文件
function curl($url, $data = array(), $method = 'get', $is_arr = "1")
{ 
    $ch = curl_init();
    switch (strtolower($method)) {
        case 'get':
            $data = http_build_query($data);
            $url .= strstr($url, '?') ? '&' . $data : '?' . $data;
            break;
        case 'post':
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            break;
        case 'put':
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            break;
        case 'delete':
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            break;
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    if ($is_arr) {
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    } else {
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    }
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $res = curl_exec($ch);
    curl_close($ch);
    if ($is_arr) {
        $res = json_decode($res, true);
    }
    return $res;
}
